<?php

namespace backend\models\form;

use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "xqlh_project_major_basis_ext".
 *
 * @property string $uuid
 * @property string $project_basic_info_id
 * @property string $major_code
 * @property string $major_name
 * @property string $major_open_date
 * @property integer $student_number
 * @property string $employment_rate
 * @property integer $px
 * @property integer $status
 * @property string $create_time
 * @property string $update_time
 * @property string $create_users_id
 * @property string $update_users_id
 */
class FormProjectMajorBasisExt extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'form_project_major_basis_ext';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uuid', 'project_basic_info_id', 'major_code', 'major_name', 'major_open_date', 'student_number', 'employment_rate', 'px', 'create_time', 'update_time', 'create_users_id', 'update_users_id'], 'required'],
            [['student_number', 'px', 'status'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['uuid', 'project_basic_info_id', 'create_users_id', 'update_users_id'], 'string', 'max' => 36],
            [['major_code', 'major_name', 'major_open_date'], 'string', 'max' => 50],
            [['employment_rate'], 'string', 'max' => 30],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uuid' => 'Uuid',
            'project_basic_info_id' => '申报项目基础信息id',
            'major_code' => '专业代码',
            'major_name' => '专业名称',
            'major_open_date' => '开设时间',
            'student_number' => '在校生数',
            'employment_rate' => '2022届毕业生就业率',
            'px' => '排序',
            'status' => '状态:1 使用;2 注销',
            'create_time' => '添加时间',
            'update_time' => '修改时间',
            'create_users_id' => '添加人|users',
            'update_users_id' => '修改人|users',
        ];
    }

    static function get_max_px($project_basic_info_id)
    {
        $data = self::find()->where([
            'project_basic_info_id' => $project_basic_info_id,
            'status' => 1,
        ])->asArray()->all();

        $pxs = ArrayHelper::getColumn($data, 'px');

        return $pxs ? max($pxs) : 0;
    }

    static function get_major_arr($project_basic_info_id)
    {
        return self::find()->where(['project_basic_info_id' => $project_basic_info_id, 'status' => 1,])->orderBy('px')->asArray()->all();
    }

    static function get_major_t($project_basic_info_id)
    {
        $data = self::get_major_arr($project_basic_info_id);

        if (!$data) return '';

        return implode('，', ArrayHelper::getColumn($data, 'major_name'));
    }
}
